#!/bin/sh
echo -e "\nFollowing Ethernet network interfaces are available:"
echo -e "\nDetecting ethernet interfaces on this device. . .\n"

# Get a list of wireless interfaces and create and array out of their names

IFACES=`iwconfig 2>&1 | grep "no wireless" | awk '{print $1}'` 
IFACES_STRING=`echo -e $IFACES`
IFS=" "
IFACES_ARR=( $IFACES_STRING )

# Loop through every wireless interface name

j=1
for ((i=0; i<${#IFACES_ARR[@]}; i++))

do
#	 Find the MAC address of the current interface

	GET_IFACE=${IFACES_ARR[$i]}
	GET_MAC=`ifconfig $GET_IFACE | grep "HWaddr" | awk '{print $5}'`

	STRCMP=`echo $GET_MAC`

	# Implement a hardware listener to get the driver detils of that interface
	
	if [ "$STRCMP" = "" ]; 	
	then

		echo ""

	else
		DRIVER_NAME=`lshw -C network | grep -B 7 $GET_MAC | grep "product"`
		VEND_NAME=`lshw -C network | grep -B 7 $GET_MAC | grep "vendor"`
		
		if [ "$DRIVER_NAME" != "" ]
		then
			if [ "$VEND_NAME" != ""  ]
			then
				let i++
				echo $i". "$GET_IFACE" - "${VEND_NAME:15}" "${DRIVER_NAME:16}
				let i--
			fi
		fi
	fi
done

# Accept the interface number from the user

echo -e "\nEnter sr. no.: "
read IFACE_NUMBER

echo -e "You entered: "$IFACE_NUMBER" - "${IFACES_ARR[$IFACE_NUMBER-1]}"\n"

# Write details into config file
echo "WAN_IFACE "${IFACES_ARR[$IFACE_NUMBER-1]} > config/wan_setup.conf


echo -e "\n***** WAN Configuration Complete *****\n"
